﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.PackageManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.PackageManagement.PackageParaVMs
{
    public partial class PackageParaListVM : BasePagedListVM<PackagePara_View, PackageParaSearcher>
    {
        
        protected override IEnumerable<IGridColumn<PackagePara_View>> InitGridHeader()
        {
            return new List<GridColumn<PackagePara_View>>{
                
                this.MakeGridHeader(x => x.PackagePara_ValueName).SetTitle(@Localizer["Page.值名称"].Value),
                this.MakeGridHeader(x => x.PackagePara_ValueMode).SetTitle(@Localizer["Page.值类型"].Value),
                this.MakeGridHeader(x => x.PackagePara_Value).SetTitle(@Localizer["Page.值"].Value),
                this.MakeGridHeader(x => x.PackagePara_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.PackagePara_Scheme).SetTitle(@Localizer["Page.方案"].Value),
                this.MakeGridHeader(x => x.PackagePara_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.PackagePara_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.PackagePara_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.PackagePara_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.PackagePara_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<PackagePara_View> GetSearchQuery()
        {
            var query = DC.Set<PackagePara>()
                
                .CheckContain(Searcher.ValueName, x=>x.ValueName)
                .CheckEqual(Searcher.ValueMode, x=>x.ValueMode)
                .CheckContain(Searcher.Value, x=>x.Value)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckEqual(Searcher.SchemeId, x=>x.SchemeId)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new PackagePara_View
                {
				    ID = x.ID,
                    
                    PackagePara_ValueName = x.ValueName,
                    PackagePara_ValueMode = x.ValueMode,
                    PackagePara_Value = x.Value,
                    PackagePara_Remark = x.Remark,
                    PackagePara_Scheme = x.Scheme.TenantCode,
                    PackagePara_CreateTime = x.CreateTime,
                    PackagePara_UpdateTime = x.UpdateTime,
                    PackagePara_CreateBy = x.CreateBy,
                    PackagePara_UpdateBy = x.UpdateBy,
                    PackagePara_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class PackagePara_View: PackagePara
    {
        
        public string PackagePara_ValueName { get; set; }
        public ValueTypeEnum? PackagePara_ValueMode { get; set; }
        public string PackagePara_Value { get; set; }
        public string PackagePara_Remark { get; set; }
        public string PackagePara_Scheme { get; set; }
        public DateTime? PackagePara_CreateTime { get; set; }
        public DateTime? PackagePara_UpdateTime { get; set; }
        public string PackagePara_CreateBy { get; set; }
        public string PackagePara_UpdateBy { get; set; }
        public bool PackagePara_IsValid { get; set; }

    }

}